package esempio.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import esempio.domain.Client;

import esempio.service.ClientService;


@Controller
@RequestMapping("/clientRegistration.htm")
@SessionAttributes("client")
public class ClientController {

	private ClientService clientService;

	@Autowired
	public void setUserService(ClientService clientService) {
		this.clientService = clientService;
	}
	
	@RequestMapping(method = RequestMethod.GET)
	public String showUserForm(ModelMap model)
	{
		Client client = new Client();
		model.addAttribute(client);
		return "clientForm";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String onSubmit(@ModelAttribute("client") Client client) {
		clientService.add(client);
		return "redirect:clientSuccess.htm";
	}
	
}
